﻿/*
 * Copyright@www.it1997.com.
 * @Author: 陈晓晨
 * @Date: 2020/6/22
 * Description:版权所有 QQ:376231445
 */

function getRequest(url) {
    var result=new Object();
    $.ajax({
        url:url,
        type:'get',
        dataTye:'json',
        async:false,
        headers:{
            "authorization":getCookie('authorization')
        },
        success(res){
           result=res
        }
    })
    return result;
}
function getRequest(url,data) {
    var result=new Object();
    $.ajax({
        url:url,
        type:'get',
        contentType:"application/json",
        dataType : "json",
        data:data,
        async:false,
        headers:{
            "authorization":getCookie('authorization')
        },
        success(res){
            result=res
        }
    })
    return result;
}
function postRequest(url,data) {
    var result=new Object();
    $.ajax({
        url:url,
        type:'post',
        contentType:"application/json",
        dataType : "json",
        data:data,
        async:false,
        headers:{
            "authorization":getCookie('authorization')
        },
        success(res){
            result=res
        }
    })
    return result;
}

function postRequestLoad(url,data) {
    var result=new Object();
var loading=layer.load();
    $.ajax({
        url:url,
        type:'post',
        contentType:"application/json",
        dataType : "json",
        data:data,
        headers:{
            "authorization":getCookie('authorization')
        },
        success(res){
	layer.close(loading);
            var index = layer.alert(res.message, {
                    title: '提示'
                }, function () {
                    // 关闭弹出层
                    layer.close(index);
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                });
        }
    })
  
}

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "": ";expires=" + exdate.toGMTString());
}
function getCookie(c_name) {
    var that = this;
    if (document.cookie.length > 0) {
        //检查这个cookie是否存在，不存在就为 -1
        c_start = document.cookie.indexOf(c_name + "=")
        if (c_start != -1) {
            //获取cookie值的开始位置
            c_start = c_start + c_name.length + 1;
            //通过";"号是否存在来判断结束位置
            c_end = document.cookie.indexOf(";", c_start);

            if (c_end == -1){
                c_end = document.cookie.length;
            }
            //通过substring()得到了值
            return unescape(document.cookie.substring(c_start, c_end))
        }
    }
}
//删除cookie
function delCookie(c_name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(c_name);
    if(cval!=null){
        document.cookie= c_name + "="+cval+";expires="+exp.toGMTString();
    }
}
//layui tree 组件
// 获取选中节点的id
function getCheckedId(jsonObj) {
    var id = "";
    $.each(jsonObj, function (index, item) {
        if (id != "") {
            id = id + "," + item.id;
        }
        else {
            id = item.id;
        }
        var i = getCheckedId(item.children);
        if (i != "") {
            id = id + "," + i;
        }
    });
    return id;
}
